package org.web2024;

import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.web.multipart.MultipartFile;
import org.web2024.service.serviceimp.AdminService;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.when;

@SpringBootTest
public class filetest {
    @Mock
    private MultipartFile coursefile;

    @InjectMocks
    private AdminService adminService;
    @Test
    public void test(){
        String csvData = "c_id,c_no,c_name,t_no,c_time,c_start_time,c_address,c_count,c_credit,t_name,c_selected,coin\n"
                + "1,CS101,Introduction to Computer Science,101,Mon 10-12,2023-09-01,Room 101,30,3,John Doe,10,5\n"
                + "2,CS102,Data Structures,102,Tue 14-16,2023-09-02,Room 102,25,4,Jane Smith,8,6\n";

        InputStream inputStream = new ByteArrayInputStream(csvData.getBytes());
        when(coursefile.getOriginalFilename()).thenReturn("courses.csv");
        //doReturn(inputStream).when(coursefile).getInputStream();

        // 调用被测试的方法
        adminService.coursefile(coursefile);
    }
}
